package org.frame.security.framework.security.service;

import javax.servlet.http.HttpServletRequest;

import org.frame.common.core.constants.Constants;
import org.frame.common.core.entity.TokenUser;
import org.frame.common.redis.RedisCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * token验证处理
 * 
 * @author ruoyi
 */
@Component
public class TokenService {

	@Autowired
	private RedisCache redisCache;

	/**
	 * 获取用户身份信息
	 * 
	 * @return 用户信息
	 */
	public TokenUser getTokenUser(HttpServletRequest request) {
		// 获取请求携带的令牌
		String userKey = Constants.LOGIN_TOKEN_KEY + request.getHeader(Constants.USER_TOKEN_HEADER);
		TokenUser user = redisCache.getCacheObject(userKey);
		return user;
	}
}
